<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<meta http-equiv="pragma" content="no-cache" />
<title>网站导航</title>
<%@ include file="../../common/Admin-list.jsp"%>
<script type="text/javascript">
 			var menu_id;
			$(function(){
				
				 $('#topic_id').combobox({
				   	 url: '../subjectTopic/listDataByAuth.json',
				   	 valueField: 'id',
				   	 textField: 'title',
				   	 editable : true,
				   	 onSelect: function (rec) { 
				   		
				   	 },
				   	onChange:function(rec)
				   	{
				   		loadMenu(rec);
				   	},
				   	 onLoadSuccess: function () { 
				   		var data = $('#topic_id').combobox('getData');
						  
			            if (data.length > 0) {
			            	var topic_id = "${data.subjectTopic.id}";
			            	if(null != topic_id && '' != topic_id){
				               $('#topic_id').combobox('select', topic_id);
			            	}else{
				                $('#topic_id').combobox('select', data[0].topic_id);
			            	}
			            }
				        }
				   	 });
			});
			
			
			
			function loadMenu(topic_id)
			{
				$('#tg').treegrid({									
					height:'500',
					width:'100%',
					rownumbers: true,
					animate:true,
					collapsible:true,
					fitColumns:true,					
					url:'../subjectMenu/getEasyUiTree.json?topic_id='+topic_id,
					method: 'post',
					idField: 'id',
					treeField: 'title',			
					showFooter:true,
					onClickRow:function (row)
					{
						menu_id=row.id;
						loadSubjectMsg(row.id);
					},
					onLoadSuccess: function (row, data) 
					{ 
				        if(data.length>0)
				        {
				        	$('#tg').treegrid('select',data[0].id);
				        	loadSubjectMsg(data[0].id);
				        } 
				    },
					toolbar: [{
		                text : '展开',
		                iconCls : 'icon-redo',
		                handler : function() {
		                    var node = $('#tg').treegrid('getSelected');		                  
		                    if (node) {		                    	
		                        $('#tg').treegrid('expand', node.id);
		                    } else {		                    	
		                        $('#tg').treegrid('expandAll');
		                    }
		                }
		            }, '-', {
		                text : '折叠',
		                iconCls : 'icon-undo',
		                handler : function() {
		                    var node = $('#tg').treegrid('getSelected');
		                    if (node) {
		                        $('#tg').treegrid('collapseAll', node.id);
		                    } else {
		                        $('#tg').treegrid('collapseAll');
		                    }
		                }
		            }, '-', {
		                text : '刷新',
		                iconCls : 'icon-reload',
		                handler : function() {
		                    $('#tg').treegrid('reload');
		                }
		            }],					
					columns:[[
						{title:'id',field:'id',hidden:true,width:10},
						{title:'parent_id',field:'parent_id',hidden:true,width:10},
						{title:'名称',field:'title',width:120},		                
					
					]]			
				})
			}
			
			
			function loadSubjectMsg(menu_id)
			{
				$('#dataGridSys').datagrid({		
					height:'505',
					width:'100%',
					rownumbers:true,//设置为true将显示行数					
					striped:true, //设置为true将交替显示行背景
					fitColumns:true,//设置为true将自动使列适应表格宽度以防止出现水平滚动
					animate:true,
					collapsible:true,
					idField:'id',//id字段
					pagination : true,//分页控件
					pageSize : 10,
				    pageList : [10, 20, 30],
				    url : '../subjectMsg/listDataWithoutContent.json?menu_id='+menu_id,
					loadMsg : '数据装载中......',
					singleSelect : true,//设置为 true，则只允许选中一行	
					onClickRow: function (rowIndex, rowData) {
						var post= $('#dataGridSys').datagrid('getSelections');
	                  },
					columns:[[					          	
								{field:'id',hidden:false,editor:{type:'text'}},
								{field:'title',title:'主题',width:120,align:'left',editor:{type:'text'}},
								{field:'state',title:'审核状态',width:20,align:'center',editor:{type:'text'},
									formatter:function(value,rec,index)
									{
										if(value=='0')
										{
											return "未审核";
										}
										else(value=='1')
										{
											return "已审";
										}
									}
								},
								{field:'source_from',title:'数据来源',width:40,align:'center',editor:{type:'text'}},
								{field:'author',title:'作者',width:40,align:'center',editor:{type:'text'}},
								{field:'editor',title:'编辑',width:40,align:'center',editor:{type:'text'}},
								{field:'createTime',title:'创建时间',width:60,align:'center',editor:{type:'text'},
									formatter:function(value,rec,index)
									{
		                        		var tday = new Date(value);
		                        		return tday.getFullYear()+"-" + (tday.getMonth() + 1) + "-" + tday.getDate() + "  "/* + tday.getHours()+":" +tday.getMinutes() */;
									}	
								},
								{field:'summary',title:'简介',width:120,align:'center',editor:{type:'text'}},
								{field:'opt',title:'操作',width:100,align:'left',  
				                    formatter:function(value,rec,index){
				                    
				                    	
			                    		var search='<a title="预览" onclick="queryYr(\''+ rec.id + '\')"  href="#">'+'<img src="<%=basePath%>pages/Admin/Images/search.gif" alt="Edit"></a>&nbsp;&nbsp;';
				                    	var edit='<a title="编辑" onclick="edit(\''+ rec.id + '\')"  href="#">'+'<img src="<%=basePath%>pages/Admin/Images/Icon/edit.gif" alt="Edit"></a>&nbsp;&nbsp;';
				                        var dele='<a title="删除" onclick="del(\''+ rec.id +'\')"  href="#">'+'<img src="<%=basePath%>pages/Admin/Images/Icon/delete.gif" alt="Delete"></a>&nbsp;&nbsp;';	
				                        var auditState='';
				                        if(rec.state=='0')
				                        {
					                        auditState='<a title="审核" onclick="audit(\''+ rec.id +'\')"  href="#">'+'<img src="<%=basePath%>pages/Admin/Images/Icon/audit.png" alt="审核"></a>&nbsp;&nbsp;';
				                        }
				                        else if(rec.state=='1')
				                        {
					                        auditState='<a title="弃审" onclick="unAudit(\''+ rec.id +'\')"  href="#">'+'<img src="<%=basePath%>pages/Admin/Images/Icon/unaudit.png" alt="弃审"></a>&nbsp;&nbsp;';
										}
											return search + edit + auditState + dele;
										}
									},

							] ],
							onLoadSuccess : function(data) {
								var rowData = data.rows;
								if (data.rows.length > 0) {
									//  $('#dataGridSys').datagrid('selectRow', 0);
									// loadMenu(rowData[0].id);
								}
							}
						});
	}

	function del(index) { //删除操作
		art.dialog({
			icon : 'question',
			width : 250,
			content : '你确定删除该数据？',
			ok : function() {
				$.ajax({
					type : 'POST',
					dataType : 'json',
					async : false,
					url : '../subjectMsg/delete.json?id=' + index,
					data : {
						ids : index,
						delSub : true
					},
					success : function(data) {
						if (data.success = true) {
							art.dialog.alert('删除成功！');
							refreshMsg();
						} else {
							art.dialog.alert('删除失败，请联系管理员！');
						}
					}
				});
			},
			cancelVal : '取消',
			cancel : true
		});

	}

	function queryYr(msgid) {
		//window.location.href="../WebSubject/detailMsgPage.htm?id="+msgid; 
		window.open("../WebSubject/detailMsgPage.htm?id=" + msgid);
	}

	function edit(id) { //编辑				
		art.dialog.open('../subjectMsg/updateInterface.htm?id=' + id, {
			title : '',
			id : 'editMsgDialog',
			lock : true,
			width : '100%',
			height : '100%'
		});
	}

	function addSub(id, topic_id) { //新增子集
		art.dialog.open('../subjectMenu/addInterface.htm?parent_id=' + id
				+ '&topic_id=' + topic_id, {
			title : '',
			lock : true,
			width : '50%',
			height : '50%'
		});
	}

	function addArticle() { //新增文章  
		var post = $('#tg').treegrid("getSelected");

		art.dialog.open('../subjectMsg/addInterface.htm?menu_id=' + post.id, {
			title : '编辑文章',
			id : 'addMsgDialog',
			lock : true,
			width : '100%',
			height : '100%'
		});
	}

	function editArticle() { //修改文章  
		var row = $('#dataGridArticleList').datagrid('getSelected');
		if (row) {
			art.dialog.open('../ArticleList/updateInterface.htm?type=edit&id='
					+ row.id, {
				title : '编辑文章',
				id : 'editMsgDialog',
				lock : true,
				width : '100%',
				height : '100%'
			});
		} else {
			$.messager.alert('系统提示', '请选择一行!', 'warning');
		}
	}

	function delArticle() { //删除操作
		var row = $('#dataGridArticleList').datagrid('getSelected');
		if (row) {
			art.dialog({
				icon : 'question',
				width : 250,
				content : '你确定删除该数据？',
				ok : function() {
					$.ajax({
						type : 'POST',
						dataType : 'json',
						async : false,
						url : '../ArticleList/delete.json',
						data : {
							ids : row.id,
							delSub : true
						},
						success : function(data) {
							if (data.success = true) {
								art.dialog.alert('删除成功！');
								refreshMsg();
							} else {
								art.dialog.alert('删除失败，请联系管理员！');
							}
						}
					});
				},
				cancelVal : '取消',
				cancel : true
			});
		} else {
			$.messager.alert('系统提示', '请选择一行!', 'warning');
		}
	}

	/*
		审核
	 */
	function audit(msgid) {
		art.dialog({
			icon : 'question',
			width : 250,
			content : '确定该数据审核通过？',
			ok : function() {
				$.ajax({
					type : 'POST',
					dataType : 'json',
					async : false,
					url : '../subjectMsg/audit.json',
					data : {
						id : msgid
					},
					success : function(data) {
						if (data.success = true) {
							art.dialog.alert('审核成功！');
							refreshMsg();
						} else {
							art.dialog.alert('审核失败，请联系管理员！');
						}
					}
				});
			},
			cancelVal : '取消',
			cancel : true
		});
	}

	function unAudit(msgid) {
		art.dialog({
			icon : 'question',
			width : 250,
			content : '确定？',
			ok : function() {
				$.ajax({
					type : 'POST',
					dataType : 'json',
					async : false,
					url : '../subjectMsg/unAudit.json',
					data : {
						id : msgid
					},
					success : function(data) {
						if (data.success = true) {
							art.dialog.alert('审核成功！');
							refreshMsg();
						} else {
							art.dialog.alert('审核失败，请联系管理员！');
						}
					}
				});
			},
			cancelVal : '取消',
			cancel : true
		});
	}

	function refreshMsg() {
		$('#dataGridSys').datagrid('reload');
	}
	function refreshMenu() {
		/* $('#tg').treegrid('reload'); */
	}
</script>
</head>
<body>
	<div>
		<div id="content" style="display: inline;">

			<div id="tgtitle" style="float: left; width: 20%;">
				<!-- 菜单 -->
				<table id="tg" style="width: 100%;"></table>
			</div>

			<div id="subject" style="float: left; width: 80%;">

				<div id="toolBar" style="height: auto; padding: 0px;">
					<!--表单  搜索栏-->
					<div id="filter" class="module">
						<ul>
							<li><label>专题主题：</label> <select id="topic_id"
								name="topic_id" class="easyui-combotree" style="width: 250px;"></select>
							</li>

							<li><input type="button" class="btn btn-blue-h20-w2"
								value="查询" onclick="searchList()" /></li>
						</ul>
						<div class="clear"></div>
					</div>
					<!--表单  列表栏-->
					<div class="list module">
						<div class="hd">
							<h2 class="t">数据列表</h2>
							<span class="handle4filter" title="显示/隐藏查询条件"></span>
						</div>
						<div class="bd">
							<div id="toolbar">
								<ul id="buttonPlace">
									<li style="paddding-right: 0px;"><a
										href="javascript:audit()"
										class="l-btn l-btn-small l-btn-plain"> <span
											class="l-btn-left l-btn-icon-left"> <span
												class="l-btn-text">审核</span> <span
												class="l-btn-icon icon-save">&nbsp;</span>
										</span>
									</a></li>
									<li><a href="javascript:addArticle()" class="icon add" 	hideFocus="false"><span class="glyphicon glyphicon-plus" style="display: in-line"></span>增加</a></li>
								</ul>
							</div>
						</div>
					</div>
				</div>
				<table id="dataGridSys" style="width: 350px;"></table>
			</div>
		</div>

	</div>
</body>
</html>